<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>加密文件传输工具</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/layui/2.5.6/css/layui.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/layui/2.5.6/layui.min.js"></script>
</head>
<body>
<div class="layui-container" style="margin-top: 30px;">
    <div class="layui-row">
        <div class="layui-col-md6">
            <div class="layui-card">
                <div class="layui-card-header">加密文件</div>
                <div class="layui-card-body">
                    <form class="layui-form">
                        <div class="layui-form-item"><label class="layui-form-label">选择文件</label>
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" id="upload_file"><i
                                        class="layui-icon">&#xe67c;</i>上传文件
                                </button>
                            </div>
                        </div>
                        <div class="layui-form-item"><label class="layui-form-label">选择加密算法</label>
                            <div class="layui-input-block"><select name="algorithm" lay-verify="required" lay-search>
                                <option value="">请选择加密算法</option>
                                <option value="AES">AES</option>
                                <option value="DES">DES</option>
                                <option value="RSA">RSA</option>
                            </select></div>
                        </div>
                        <div class="layui-form-item"><label class="layui-form-label">输入密钥</label>
                            <div class="layui-input-block"><input type="password" name="key" placeholder="请输入密钥"
                                                                  autocomplete="off" class="layui-input"></div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="encrypt"><i
                                        class="layui-icon">&#xe67c;</i>加密
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-card">
                <div class="layui-card-header">解密文件</div>
                <div class="layui-card-body">
                    <form class="layui-form">
                        <div class="layui-form-item"><label class="layui-form-label">选择文件</label>
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" id="upload_encrypted_file"><i
                                        class="layui-icon">&#xe67c;</i>上传加密文件
                                </button>
                            </div>
                        </div>
                        <div class="layui-form-item"><label class="layui-form-label">选择解密算法</label>
                            <div class="layui-input-block"><select name="algorithm" lay-verify="required" lay-search>
                                <option value="">请选择解密算法</option>
                                <option value="AES">AES</option>
                                <option value="DES">DES</option>
                                <option value="RSA">RSA</option>
                            </select></div>
                        </div>
                        <div class="layui-form-item"><label class="layui-form-label">输入密钥</label>
                            <div class="layui-input-block"><input type="password" name="key" placeholder="请输入密钥"
                                                                  autocomplete="off" class="layui-input"></div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="decrypt"><i
                                        class="layui-icon">&#xe67c;</i>解密
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script> layui.use(['form', 'upload'], function () {
    var form = layui.form;
    var upload = layui.upload;

    // 上传文件
    upload.render({
        elem: '#upload_file',
        url: '/upload',
        accept: 'file',
        done: function (res) {
            console.log(res);
        },
        error: function () {
            layer.msg('上传失败');
        }
    });

    // 上传加密文件
    upload.render({
        elem: '#upload_encrypted_file',
        url: '/upload',
        accept: 'file',
        done: function (res) {
            console.log(res);
        },
        error: function () {
            layer.msg('上传失败');
        }
    });

    // 加密
    form.on('submit(encrypt)', function (data) {
        console.log(data.field);
        return false;
    });

    // 解密
    form.on('submit(decrypt)', function (data) {
        console.log(data.field);
        return false;
    });
});
</script>

</body>
</html>
